package com.siburian.MyStuff;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.*;

public class LearnMatemathic extends Activity {
	int tempIndexNaik = 0;
	int tempIndexArray = 0;
	String[] pertanyaan;
	int jumlahPertanyaan = 0;
	TextView txt1, txt2, txt3, txt4, txt5, txt6, txt7, txt8, txt9, txt10;
	int tempRandom = 0;
	String jenisOperan = "";
	int[] nilaiPertama, nilaiKedua, resultLearn;
	int indexCount = 0;
	Button btnNextLearnBasic, btnPreviousLearnBasic;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.learn_matemathic);
		txt1 = (TextView) findViewById(R.id.txtLearnMatemathic_1);
		txt2 = (TextView) findViewById(R.id.txtLearnMatemathic_2);
		txt3 = (TextView) findViewById(R.id.txtLearnMatemathic_3);
		txt4 = (TextView) findViewById(R.id.txtLearnMatemathic_4);
		txt5 = (TextView) findViewById(R.id.txtLearnMatemathic_5);
		txt6 = (TextView) findViewById(R.id.txtLearnMatemathic_6);
		txt7 = (TextView) findViewById(R.id.txtLearnMatemathic_7);
		txt8 = (TextView) findViewById(R.id.txtLearnMatemathic_8);
		txt9 = (TextView) findViewById(R.id.txtLearnMatemathic_9);
		txt10 = (TextView) findViewById(R.id.txtLearnMatemathic_10);
		btnNextLearnBasic = (Button) findViewById(R.id.btnNextLearnMatemathic);
		btnPreviousLearnBasic = (Button) findViewById(R.id.btnPreviousLearnMatemathic);
		Random generator = new Random();
		jenisOperan = "tambah";
		jumlahPertanyaan = 20;
		nilaiPertama = new int[jumlahPertanyaan * 10];
		nilaiKedua = new int[jumlahPertanyaan * 10];
		resultLearn = new int[jumlahPertanyaan * 10];
		pertanyaan = new String[jumlahPertanyaan * 10];
		for (int j = 0; j < 10; j++) {
			tempIndexNaik = 50 * j;
			for (int i = 0; i < jumlahPertanyaan; i++) {
				tempRandom = generator.nextInt(10);
				tempRandom = tempIndexNaik + tempRandom;
				tempIndexArray = j * 10;
				nilaiPertama[i + tempIndexArray] = tempRandom;
				tempRandom = generator.nextInt(10);
				tempRandom = tempIndexNaik + tempRandom;
				if (jenisOperan == "kurang") {
					while (nilaiPertama[i] < tempRandom) {
						tempRandom = generator.nextInt(10);
						tempRandom = tempIndexNaik + tempRandom;
						nilaiPertama[i + tempIndexArray] = tempRandom;
					}
				}
				nilaiKedua[i] = tempRandom;
			}
		}
		for (int j = 0; j < 10; j++) {
			for (int i = 0; i < jumlahPertanyaan; i++) {
				tempIndexArray = j * 10;
				if (jenisOperan == "tambah") {
					resultLearn[i + tempIndexArray] = nilaiPertama[i
							+ tempIndexArray]
							+ nilaiKedua[i + tempIndexArray];
				}
				if (jenisOperan == "kali") {
					resultLearn[i + tempIndexArray] = nilaiPertama[i
							+ tempIndexArray]
							* nilaiKedua[i + tempIndexArray];
				}
				if (jenisOperan == "kurang") {
					resultLearn[i + tempIndexArray] = nilaiPertama[i
							+ tempIndexArray]
							- nilaiKedua[i + tempIndexArray];
				}
			}
		}
		for (int j = 0; j < 10; j++) {
			for (int i = 0; i < jumlahPertanyaan; i++) {
				tempIndexArray = j * 10;
				if (jenisOperan == "tambah") {
					pertanyaan[i + tempIndexArray] = " "
							+ nilaiPertama[i + tempIndexArray] + " + "
							+ nilaiKedua[i + tempIndexArray] + " = "
							+ resultLearn[i + tempIndexArray];
				}
				if (jenisOperan == "kali") {
					pertanyaan[i + tempIndexArray] = " "
							+ nilaiPertama[i + tempIndexArray] + " * "
							+ nilaiKedua[i + tempIndexArray] + " = "
							+ resultLearn[i + tempIndexArray];
				}
				if (jenisOperan == "kurang") {
					pertanyaan[i + tempIndexArray] = " "
							+ nilaiPertama[i + tempIndexArray] + " - "
							+ nilaiKedua[i + tempIndexArray] + " = "
							+ resultLearn[i + tempIndexArray];
				}
			}
		}
		txt1.setText(pertanyaan[0]);
		txt2.setText(pertanyaan[1]);
		txt3.setText(pertanyaan[2]);
		txt4.setText(pertanyaan[3]);
		txt5.setText(pertanyaan[4]);
		txt6.setText(pertanyaan[5]);
		txt7.setText(pertanyaan[6]);
		txt8.setText(pertanyaan[7]);
		txt9.setText(pertanyaan[8]);
		txt10.setText(pertanyaan[9]);
		btnNextLearnBasic.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(indexCount == 90){
				btnNextLearnBasic.setEnabled(false);
				}
				indexCount += 10;
				btnNextLearnBasic.setEnabled(true);
				txt1.setText(pertanyaan[0 + indexCount]);
				txt2.setText(pertanyaan[1 + indexCount]);
				txt3.setText(pertanyaan[2 + indexCount]);
				txt4.setText(pertanyaan[3 + indexCount]);
				txt5.setText(pertanyaan[4 + indexCount]);
				txt6.setText(pertanyaan[5 + indexCount]);
				txt7.setText(pertanyaan[6 + indexCount]);
				txt8.setText(pertanyaan[7 + indexCount]);
				txt9.setText(pertanyaan[8 + indexCount]);
				txt10.setText(pertanyaan[9 + indexCount]);
			}
		});
		btnPreviousLearnBasic.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(indexCount == 0){
				btnPreviousLearnBasic.setEnabled(false);
				}else{
				btnPreviousLearnBasic.setEnabled(true);
				indexCount -= 10;
				txt1.setText(pertanyaan[0 + indexCount]);
				txt2.setText(pertanyaan[1 + indexCount]);
				txt3.setText(pertanyaan[2 + indexCount]);
				txt4.setText(pertanyaan[3 + indexCount]);
				txt5.setText(pertanyaan[4 + indexCount]);
				txt6.setText(pertanyaan[5 + indexCount]);
				txt7.setText(pertanyaan[6 + indexCount]);
				txt8.setText(pertanyaan[7 + indexCount]);
				txt9.setText(pertanyaan[8 + indexCount]);
				txt10.setText(pertanyaan[9 + indexCount]);
				}
			}
		});
	}
}
